<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<body class="hold-transition skin-blue sidebar-mini">
<section class="content-header">
    <h1>成本信息输出查询</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" onsubmit="return false;">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group">
                                    <label for="query-proCode">项目编号</label>
                                    <input id="query-proCode" type="text" name="proCode" class="form-control"
                                           placeholder="请输入项目编号">
                                </div>
                                <div class="form-group">
                                    <label for="query-proName">项目名称</label>
                                    <input id="query-proName" type="text" name="proName" class="form-control"
                                           placeholder="请输入项目名称">
                                </div>
                                <div class="form-group">
                                    <label for="query-busSpecialId">专业</label>
                                    <select id="query-busSpecialId" class="form-control" name="busSpecialId">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1" >机械</option>
                                        <option value="2">自动化</option>
                                        <option value="3">流体</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-proPart">部分</label>
                                    <input id="query-proPart" type="text" name="proPart" class="form-control"
                                           placeholder="请输入部分">
                                </div>
                                <div class="form-group">
                                    <label for="query-createName">提报人</label>
                                    <input id="query-createName" type="text" name="createName" class="form-control"
                                           placeholder="请输入提报人">
                                </div>

                                <div class="form-group">
                                    <label for="query-costType">成本类型</label>
                                    <select id="query-costType" class="form-control" name="costType">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="1" >设计工时确认单</option>
                                        <option value="2">下料工时计划单</option>
                                        <option value="3">铆焊工时计划单</option>
                                        <option value="4" >热处理计划单</option>
                                        <option value="5">装配工时计划单</option>
                                        <option value="6">涂装工时计划单</option>
                                        <option value="7" >安装工时计划单</option>
                                        <option value="8">调试工时确认单</option>
                                        <option value="9">机加工时计划单</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-status">提报状态</label>
                                    <select id="query-status" class="form-control" name="status">
                                        <option value="">请选择</option>
                                        <option value="1" >未提交</option>
                                        <option value="2">未审核</option>
                                        <option value="3">审核中</option>
                                        <option value="4" selected="selected">已审核</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-receiveStatus">接收状态</label>
                                    <select id="query-receiveStatus" class="form-control" name="receiveStatus">
                                        <option value="" selected="selected">请选择</option>
                                        <option value="0" >未接收</option>
                                        <option value="1">已接收</option>
                                    </select>
                                </div>
                                <div class="form-group">
                                    <label for="query-startTime">提报日期</label>
                                    <input id="query-startTime" type="text" class="form-control datepicker"
                                           name="startTime"
                                           readonly="readonly"/>
                                    <label for="query-endTime"> 至 </label>
                                    <input id="query-endTime" type="text" class="form-control datepicker" name="endTime"
                                           readonly="readonly"/>
                                </div>
                                <button type="button" class="btn btn-success" id="btn-search"
                                        onclick="js.table.search(table)">
                                    <span class="Bold">搜索</span>
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="box-body">
                    <table id="bootstrap-table" style="width: 99.9%;"></table>
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">

    let table;
    var statusType = ["", "未开始", "执行中", "已完成", "不需要"];
    var statusColor = ["", "", "#f39c12", "#00a65a", "#00acd6"];

    function yearSelectCreate() {
        var myDate = new Date();
        var endYear = myDate.getFullYear();
        for (var i = endYear; i >= 2016; i--) {
            if (i === 2016)
                $("#query-year").append("<option value='" + i + "'>" + i + "年及以前" + "</option>");
            else
                $("#query-year").append("<option value='" + i + "'>" + i + "年" + "</option>");
        }
    }

    /**
     * 合并单元格
     * @param data  原始数据（在服务端完成排序）
     * @param fieldName 合并属性名称
     * @param fiedArry 待合并列
     * @param colspan   合并列
     * @param target    目标表格对象
     */
    function mergeCells(data, fieldName, fiedArry, colspan, target) {
        var valueArry = new Array();//数组只记录值
        for (var i = 0; i < data.length; i++) {
            for (var prop in data[i]) {
                if (prop == fieldName) {
                    var key = data[i][prop]
                    valueArry[i] = key;
                    break;
                }
            }
        }

        var numArry = new Array();//记录值出现的次数  一会就通过循环次数组  合并单元格
        var value = valueArry[0];//初始值
        var num = 0;//记录值出现的次数
        var index1 = 0;//numArry的下标
        for (var i = 0; i <= valueArry.length; i++) {
            if (i == valueArry.length) {//解决最后一次赋值
                numArry[index1] = num;
                break;
            }
            if (value == valueArry[i]) {
                num++;//list下一个值与变量value值相同时，num+1，下标不变
            } else {
                value = valueArry[i];//如果值不相等就把下一个值   赋值给value变量
                numArry[index1] = num;//把value变量之前的值 出现的次数记录下来
                num = 1;// 新的value值出现一次
                index1++;//下标+1;
            }
        }

        var index = 0;
        for (var i = 0; i < numArry.length; i++) {
            var count = numArry[i] * 1;
            $(target).bootstrapTable('mergeCells', {
                index: index,
                field: fiedArry,
                colspan: colspan,
                rowspan: count
            });
            index += count;
        }
    }


    $(function () {
        yearSelectCreate();

        /** 设计进度列表 */
        table = js.table.init({
            url: ctx + "craft/cost/list",
            onLoadSuccess: function (data) {
                var dataSource = $('#bootstrap-table').bootstrapTable('getData', true);
                // mergeCells(dataSource, "mergeFlg", "submit", 1, $('#bootstrap-table')); //合并单元格
                // mergeCells(dataSource, "proId", "proCode", 1, $('#bootstrap-table')); //合并单元格
                // mergeCells(dataSource, "proId", "proName", 1, $('#bootstrap-table')); //合并单元格
                // mergeCells(dataSource, "proId", "proNum", 1, $('#bootstrap-table')); //合并单元格
                // // mergeCells(dataSource, "proId", "special", 1, $('#bootstrap-table')); //合并单元格
                // mergeCells(dataSource, "proId", "rejectReason", 1, $('#bootstrap-table')); //合并单元格
            },
            columns: [
                {

                    title: '序号', field: 'id', width: '50',
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {title: "项目编号", field: 'proCode'},
                {title: "项目名称", field: 'proName'},
                {title: "数量", field: 'proNum'},
                {title: "专业", field: 'special'},
                {title: "部分", field: 'proPart'},
                {
                    title: "成本类型", field: 'costType',
                    formatter: function(value, row, index){
                        if(value==1){
                            return '<span >设计工时确认单</span>';
                        }else if(value==2){
                            return '<span >下料工时计划单</span>';
                        }else if(value==3){
                            return '<span>铆焊工时计划单</span>';
                        }else if(value==4){
                            return '<span >热处理</span>';
                        }else if(value==5){
                            return '<span>装配工时计划单</span>';
                        }else if(value==6){
                            return '<span >涂装工时计划单</span>';
                        }else if(value==7){
                            return '<span >安装工时计划单</span>';
                        }else if(value==8){
                            return '<span>调试工时确认单</span>';
                        }else if(value==9){
                            return '<span>机加工时计划单</span>';
                        }
                    }
                },
                {
                    title: "提报状态", field: 'status',
                    formatter: function(value, row, index){
                        if(value==1){
                            return '<span class="label badge bg-gray">未提交</span>';
                        }else if(value==2){
                            return '<span class="label badge bg-yellow">未审核</span>';
                        }else if(value==3){
                            return '<span class="label badge bg-blue">审核中</span>';
                        }else if(value==4){
                            return '<span class="label badge bg-green">已审核</span>';
                        }
                    }
                },
                {title: "提报人", field: 'createName'},
                {title: "提报日期", field: 'createTime'},
                {title: "审核人", field: 'verifyName'},
                {
                    title: "接收状态", field: 'receiveStatus',
                    formatter: function(value, row, index){
                        if(value==0){
                            return '<span class="label badge bg-gray">未接收</span>';
                        }else if(value==1){
                            return '<span class="label badge bg-green">已接收</span>';
                        }
                    }
                },
                {
                    title: "操作", field: 'operate',
                    formatter: function (value, row) {
                        let actions = [];
                        actions.push('<a class="btn btn-info btn-xs" target="_blank" href="' + ctx + 'craft/cost/queryDetail/' + row.id + '"> 查看</a> ');
                        return actions.join('');
                    }
                },

            ]
        });
    });
    /** 删除数据 */
    function del(id) {
        js.modal.confirm("将删除主单及明细所有数据！！  确认删除吗？", function () {
            js.post({
                url: ctx + "craft/cost/blanking/del",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
    /** 提交数据待审核 */
    function submit(id) {
        js.modal.confirm("确定要提交本项目所有未提交的计划单吗？", function () {
            js.post({
                url: ctx + "craft/cost/blanking/submit",
                data: {id: id},
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.success(result.msg);
                        js.table.refresh(table);
                    } else {
                        js.modal.warning(result.msg);
                    }
                }
            })
        })
    }
</script>
</body>
</html>
